
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.Except;
import cn.edu.scau.cmi.hombio.domain.ExceptionType;
import cn.edu.scau.cmi.hombio.domain.Task;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class ExceptServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected ExceptService service;

	/**
	 * Instantiates a new ExceptServiceTest.
	 *
	 */
	public ExceptServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Delete an existing ExceptionType entity
	* 
	 */
	@Test
	public void deleteExceptExceptionType() {
		// TODO: JUnit - Populate test inputs for operation: deleteExceptExceptionType 
		Integer except_id = 0;
		Integer related_exceptiontype_id = 0;
		Except response = null;
		response = service.deleteExceptExceptionType(except_id, related_exceptiontype_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteExceptExceptionType
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveExceptTask() {
		// TODO: JUnit - Populate test inputs for operation: saveExceptTask 
		Integer id = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		Except response = null;
		response = service.saveExceptTask(id, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: saveExceptTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteExceptTask() {
		// TODO: JUnit - Populate test inputs for operation: deleteExceptTask 
		Integer except_id_1 = 0;
		Integer related_task_id = 0;
		Except response = null;
		response = service.deleteExceptTask(except_id_1, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteExceptTask
	}

	/**
	 * Operation Unit Test
	* Save an existing Except entity
	* 
	 */
	@Test
	public void saveExcept() {
		// TODO: JUnit - Populate test inputs for operation: saveExcept 
		Except except = new cn.edu.scau.cmi.hombio.domain.Except();
		service.saveExcept(except);
	}

	/**
	 * Operation Unit Test
	* Load an existing Except entity
	* 
	 */
	@Test
	public void loadExcepts() {
		Set<Except> response = null;
		response = service.loadExcepts();
		// TODO: JUnit - Add assertions to test outputs of operation: loadExcepts
	}

	/**
	 * Operation Unit Test
	* Save an existing Employee entity
	* 
	 */
	@Test
	public void saveExceptEmployee() {
		// TODO: JUnit - Populate test inputs for operation: saveExceptEmployee 
		Integer id_1 = 0;
		Employee related_employee = new cn.edu.scau.cmi.hombio.domain.Employee();
		Except response = null;
		response = service.saveExceptEmployee(id_1, related_employee);
		// TODO: JUnit - Add assertions to test outputs of operation: saveExceptEmployee
	}

	/**
	 * Operation Unit Test
	* Delete an existing Except entity
	* 
	 */
	@Test
	public void deleteExcept() {
		// TODO: JUnit - Populate test inputs for operation: deleteExcept 
		Except except_1 = new cn.edu.scau.cmi.hombio.domain.Except();
		service.deleteExcept(except_1);
	}

	/**
	 * Operation Unit Test
	* Return a count of all Except entity
	* 
	 */
	@Test
	public void countExcepts() {
		Integer response = null;
		response = service.countExcepts();
		// TODO: JUnit - Add assertions to test outputs of operation: countExcepts
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findExceptByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findExceptByPrimaryKey 
		Integer id_2 = 0;
		Except response = null;
		response = service.findExceptByPrimaryKey(id_2);
		// TODO: JUnit - Add assertions to test outputs of operation: findExceptByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Save an existing ExceptionType entity
	* 
	 */
	@Test
	public void saveExceptExceptionType() {
		// TODO: JUnit - Populate test inputs for operation: saveExceptExceptionType 
		Integer id_3 = 0;
		ExceptionType related_exceptiontype = new cn.edu.scau.cmi.hombio.domain.ExceptionType();
		Except response = null;
		response = service.saveExceptExceptionType(id_3, related_exceptiontype);
		// TODO: JUnit - Add assertions to test outputs of operation: saveExceptExceptionType
	}

	/**
	 * Operation Unit Test
	* Return all Except entity
	* 
	 */
	@Test
	public void findAllExcepts() {
		// TODO: JUnit - Populate test inputs for operation: findAllExcepts 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Except> response = null;
		response = service.findAllExcepts(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllExcepts
	}

	/**
	 * Operation Unit Test
	* Delete an existing Employee entity
	* 
	 */
	@Test
	public void deleteExceptEmployee() {
		// TODO: JUnit - Populate test inputs for operation: deleteExceptEmployee 
		Integer except_id_2 = 0;
		Integer related_employee_id = 0;
		Except response = null;
		response = service.deleteExceptEmployee(except_id_2, related_employee_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteExceptEmployee
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
